﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Station;
using System.IO;

namespace AutoMachine
{
    public partial class Frm_Station : Form
    {
        Tool.AutoResize FormResize = new Tool.AutoResize();//窗体缩放实例化    

        public Frm_Station()
        {
            InitializeComponent();
        }

        #region 窗体实例化
        /// <summary>
        /// 窗体实例化
        /// </summary>
        private static Frm_Station _instance;
        public static Frm_Station Instance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                    _instance = new Frm_Station();
                return _instance;
            }
        }
        #endregion

        private void Frm_Station_Load(object sender, EventArgs e)
        {
            CSName();

            FormResize.SetAutoResize(this);//窗体缩放实例化   
        }

        //1获取Station的路径
        public void CSName()
        {
            DirectoryInfo path = new DirectoryInfo(Application.StartupPath);//起始路径
            string ma = path.Parent.FullName;//路径的上一层
            string pathname = ma + "\\" + "AutoMachine" + "\\" + "Station";

            //遍历文件夹下的CS文件
            DirectoryInfo fdir = new DirectoryInfo(pathname);

            FileInfo[] files = fdir.GetFiles("*.cs");

            this.treeView1.Nodes.Add("类名称");

            foreach (FileInfo d in files)//遍历文件夹
            {
                if (d.Name != "StationBase.cs")
                {
                    //添加子节点  
                    treeView1.Nodes[0].Nodes.Add(d.Name);
                }
            }

            this.treeView1.ExpandAll();//全展开
        }


        /// <summary>
        /// 读取CS文件中的内容到RichTextBox中
        /// </summary>

        public void ReadCS(string path)
        {
            this.richTextBox1.ResetText();

            string[] strArray = File.ReadAllLines(path);

            for (int i = 0; i < strArray.Length; i++)
            {
                Tool.CtrDisplay.AddTextToRichTextBox(this.richTextBox1, strArray[i],false);             
            }

        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            DirectoryInfo path = new DirectoryInfo(Application.StartupPath);//起始路径
            string file = path.Parent.FullName;//路径的上一层
            string pathname = file + "\\" + "AutoMachine" + "\\" + "Station";

            if (treeView1.SelectedNode.Parent == null)
            {
                return;
            }

            //string name = ((TreeView)sender).SelectedNode.Text;//子节点名称

            string PathName = pathname + "\\"+ ((TreeView)sender).SelectedNode.Text; ;

            ReadCS(PathName);

            
        }

      

        //读取特定行 结束行 



    }
}  

